<%@ page language="java" import="com.erclab.internal.xpresso.security.User, com.erclab.internal.xpresso.conf.*"%>
<% 	User currentUser = (User)session.getAttribute("user"); 
	if (currentUser != null && currentUser.getIdUser() != 0){
		// User already logged in
	} else {
		String cookieName = "xpressouser";
		Cookie cookies [] = request.getCookies ();
		Cookie myCookie = null;
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) { 
				if (cookies [i].getName().equals (cookieName)){
					myCookie = cookies[i];	
					break;
				}
			}
		}
		if (myCookie != null && ! myCookie.getValue().equalsIgnoreCase("guest")){
			if (currentUser == null) {
				currentUser = new User();
			}
			currentUser.setUserName(myCookie.getValue());
			currentUser.setNetId(myCookie.getValue());
			currentUser.setIpAddress(request.getRemoteAddr());
			Settings.getUserDirectory().loadUserBean(currentUser);	
			Settings.getUserDirectory().addVisitEntry(currentUser);	
			session.setAttribute("user", currentUser);
		}
	}
	
%>